package com.feri.rbacsys.controller;



import com.feri.rbacsys.bo.PermissionAddBo;
import com.feri.rbacsys.bo.PermissionBo;
import com.feri.rbacsys.service.intf.PermissionService;
import com.feri.rbacsys.service.intf.RoleService;
import com.feri.rbacsys.vo.R;
import io.swagger.annotations.Api;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 18.权限表(SysPermission)表控制层
 *
 * @author makejava
 * @since 2023-03-26 10:40:28
 */
@RestController
@RequestMapping("/erp/api/permission/")
@Api(tags = "权限相关接口")
public class PermissionController {
    /**
     * 服务对象
     */
    @Resource
    private PermissionService service;
    @Resource
    private RoleService roleService;

    /**
     * 新增权限或菜单
     */
    @PreAuthorize("hasAuthority('perm:add')")
    @PostMapping("add")
    public R add(@RequestBody PermissionBo bo){
        return service.add(bo);
    }

    /**
     * 查询-列表
     */
    @PreAuthorize("hasAuthority('perm:page')")
    @GetMapping("page")
    public R page(){
        return service.queryAll();
    }

    /**
     * 查询-我的菜单
     */
    @PreAuthorize("hasAuthority('perm:menu')")
    @GetMapping("menu")
    public R menu(){
        return service.queryMenuByUid();
    }

    /**
     * 查询-我的菜单
     */
    @PreAuthorize("hasAuthority('perm:menu3')")
    @GetMapping("menuvue3")
    public R menuVue3(){
        return service.queryMenuByUid();
    }

    /**
     * 查询-我的权限列表
     */
    // @PreAuthorize("hasAuthority('perm:perms')")
    @GetMapping("perms")
    public R perms(){
        return service.queryPermByUid();
    }

    /**
     * 删除角色及其权限
     * @param rid
     * @return
     */
    @PreAuthorize("hasAuthority('perm:del')")
    @DeleteMapping("del")
    public R delRole(int rid) {
        return roleService.del(rid);
    }

    /**
     * 修改角色对应的权限或菜单
     */
    @PreAuthorize("hasAuthority('perm:update')")
    @PostMapping("update")
    public R updateRp(@RequestBody PermissionAddBo bo){
        return service.updateByUid(bo);
    }
}
